package com.cea.papyrus.diagram.classdiagram.commands;

import org.eclipse.uml2.uml.TemplateParameter;
import org.eclipse.uml2.uml.TemplateSignature;

import com.cea.papyrus.core.commands.PapyrusCommand;

public class TemplateParameterReferenceCreateCommand extends PapyrusCommand {

//	public final static int PARAMETERED_ELEMENT = 0 ;
//	public final static int DEFAULT = 1 ;
//	public final static int CONSTRAINING_CLASSIFIER = 2 ;
	
	/**
	 * target uml signature.
	 */
	private TemplateSignature umlTemplateSignature ;
	
	/**
	 * the template parameter to be referenced
	 */
	private TemplateParameter referencedParameter ;
	
	
	public TemplateParameterReferenceCreateCommand(Class elementClass, TemplateSignature umlTemplateSignature, TemplateParameter referencedParameter) {
//		super(elementClass) ; // this statement is useless
		this.umlTemplateSignature = umlTemplateSignature ;
		this.referencedParameter = referencedParameter ;
		this.setLabel("Create template parameter reference") ;
	}
	
	public void execute() {
		umlTemplateSignature.getParameters().add(referencedParameter) ;
	}
	
	public boolean canExecute() {
		return true ; 
	}
	
	public void redo() {
		execute() ;
	}
	
	public void undo() {
		umlTemplateSignature.getParameters().remove(referencedParameter) ;
	}
	
	public boolean canUndo() {
		return referencedParameter != null ;
	}
	
	public boolean canRedo() {
		return referencedParameter != null ;
	}
}
